package com.petAdoption.manager.controller;


import com.petAdoption.manager.entity.Petage;
import com.petAdoption.manager.service.IPetageService;
import com.petAdoption.manager.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/petage")

public class PetageController {
    @Resource
    private IPetageService petageService;
    @Resource
    private Result result;

    @GetMapping("/findAll")
    public Result findAll(){
        List<Petage> list = petageService.findAll();
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }


    @DeleteMapping("/delPetAge")
    public Result delPetAge(Integer petageId){
        int rows = petageService.delPetAge(petageId);
        if(rows>0){
            return result.success("删除成功",rows);
        }else {
            return result.fail("删除失败");
        }
    }


    @PostMapping("/addPetAge")
    public Result addPetAge(@RequestBody Petage petage){
        int rows = petageService.addPetAge(petage);
        if(rows>0){
            return result.success("添加成功",rows);
        }else {
            return result.fail("添加失败");
        }
    }

    @PutMapping("/updatePetType")
    public Result updatePetType(@RequestBody Petage petage){
        //System.out.println(petage.getPetageType());
        int rows = petageService.updatePetType(petage);
        if(rows>0){
            return result.success("修改成功",rows);
        }else {
            return result.fail("修改失败");
        }
//       boolean row = petageService.updateById(petage);
//       if (row)return result.success();
//       return result.fail();
    }

}
